import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:getx_learn/app/common/widgets/widgets.dart';

import '../controllers/fun_response4_controller.dart';

class FunResponse4View extends GetView<FunResponse4Controller> {
  const FunResponse4View({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppBar(context: context, title: "ValueBuilder<int>的使用"),
      body: Column(
          children: [
            Text("""
            https://ducafecat.tech/2021/04/16/flutter-getx/flutter-getx-03-state-dependency/
            
            https://liujunmin.com/flutter/getx/getx_controller.html
            
            适合局部的状态管理，很灵活。
            """),
            Center(
              child: ValueBuilder<int?>(
                initialValue: 10,
                builder: (value, updateFn) {
                  return Column(
                     children: [
                       Text("count -> " + value.toString()),
                       ElevatedButton(
                         onPressed: () {
                           updateFn(value! + 1);
                         },
                         child: Text('ValueBuilder -> add'),
                       )
                     ],
                  );
                },


                // builder: (value, updateFn) => Switch(
                //   value: value,
                //   onChanged:
                //       updateFn, // same signature! you could use ( newValue ) => updateFn( newValue )
                // ),
                // if you need to call something outside the builder method.
                onUpdate: (value) => print("Value updated: $value"),
                onDispose: () => print("Widget unmounted"),
              ),
            )
          ],
        ),
    );
  }
}
